#include<iostream>
#include<vector>
#include<map>
using namespace std;

class Solution {
public:
    map<int,bool>bol;
    vector<vector<int>>ans;
    void dfs(int u,int n,vector<int>& nums,vector<int>& tmp)
    {
        
        if(u==n){
            ans.push_back(tmp);
            tmp.clear();
            return ;
        }
        for(int i=0;i<n;i++)
        {
            if(bol[nums[i]])
            {
                tmp[u]=nums[i];
                bol[nums[i]]=false;
                dfs(u+1,n,nums,tmp);
                bol[nums[i]]=true;
            }
        }
    }
    vector<vector<int>> permute(vector<int>& nums) {
        
        for(int i=0;i<nums.size();i++)bol[nums[i]]=true;
        vector<int>tmp(nums.size());
        dfs(0,nums.size(),nums,tmp);
        return ans;
    }
};
int main()
{
    Solution s1;
    vector<int>nums({1,2,3});
    s1.permute(nums);
}